import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
export type UserResult = {
  success: boolean;
  data: {
    /** 头像 */
    avatar: string;
    /** 用户名 */
    username: string;
    /** 昵称 */
    nickname: string;
    /** 当前登录用户的角色 */
    roles: Array<string>;
    /** 按钮级别权限 */
    permissions: Array<string>;
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};
export type UserInfo = {
  /** 用户名 */
  username: string;
  /** 昵称*/
  nickname: string;
  /** 姓名 */
  name: string;
  /** 密码 */
  password: string;
  /** 邮箱 */
  email: string;
  /** 联系电话 */
  phone: string;
  /** 入职时间 */
  entryDate: string;
  /** 职位 */
  jobTitleId: string;
  /** 性别 */
  gender: string;
  /** 状态 */
  status: string;
  /** 部门 */
  departmentId: string;
  /** 备注 */
  remarks: string;
};
export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", baseUrlApi + "/user/login", { data });
};

/** 刷新`token` */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>("post", baseUrlApi + "/refresh-token", { data });
};
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
};
type ResultDelete = {
  code: number;
  msg: string;
};
type ResultCreate = {
  code: number;
  msg: string;
};
/** 用户列表 */
export const getUserListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/user/list", {
    params
  });
};
/** 用户职位列表 */
export const getJobTitleListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/jobTitle/select", {
    params
  });
};
/** 用户职位添加 */
export const jobTitleStoreApi = (params?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/jobTitle/store", {
    params
  });
};

/** 添加 */
export const createUserApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/user/store", {
    data
  });
};
/** 修改 */
export const updateUserApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/user/update", {
    data
  });
};
/** 用户状态修改 */
export const updateUserStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/user/updateStatus", {
    data
  });
};
/** 修改用户密码 */
export const updateUserPassWordApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/user/updatePassword", {
    data
  });
};
/** 删除用户 */
export const delUserApi = (params?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/user/delete", {
    params
  });
};
type Show = {
  code: number;
  msg: string;
  result?: any;
};
/** 用户详情 */
export const getUserShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/user/show", {
    params
  });
};
/** 用户选项 */
export const userSelectApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/user/select", {
    params
  });
};
/** 用户选项 */
export const getUserSelectOptionsApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/user/selectOptions", {
    params
  });
};
/** 部门列表树 */
export const getDeptListApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/department/listTree", {
    params
  });
};
/** 部门列表 */
export const getDepartmentListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/department/list", {
    params
  });
};
/** 部门添加 */
export const createDepartmentApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/department/store", {
    data
  });
};
/** 部门修改 */
export const updateDepartmentApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/department/update", {
    data
  });
};
/** 部门删除 */
export const delDepartmentApi = (params?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/department/delete", {
    params
  });
};
/** 部门详情 */
export const getDepartmentShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/department/show", {
    params
  });
};
/** 菜单列表 */
export const getRbacMenuListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/rbacMenu/list", {
    params
  });
};
/** 菜单添加 */
export const createRbacMenuApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/rbacMenu/store", {
    data
  });
};
/** 菜单修改 */
export const updateRbacMenuApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/rbacMenu/update", {
    data
  });
};
/** 菜单删除 */
export const delRbacMenuApi = (params?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/rbacMenu/delete", {
    params
  });
};
/** 菜单详情 */
export const getRbacMenuShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/rbacMenu/show", {
    params
  });
};
/** 菜单选择 */
export const getRbacMenuListTreeApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/rbacMenu/select", {
    params
  });
};
/** 菜单已用图标 */
export const getRbacMenuIconIndexApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/rbacMenu/iconIndex", {
    params
  });
};
/** 菜单状态修改 */
export const getRbacMenuUpdateStatusApi = (params?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/rbacMenu/updateStatus", {
    params
  });
};
/** 角色列表 */
export const getRbacRoleListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/rbacRole/list", {
    params
  });
};
/** 菜单添加 */
export const createRbacRoleApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/rbacRole/store", {
    data
  });
};
/** 菜单修改 */
export const updateRbacRoleApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/rbacRole/update", {
    data
  });
};
/** 菜单删除 */
export const delRbacRoleApi = (params?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/rbacRole/delete", {
    params
  });
};
/** 菜单详情 */
export const getRbacRoleShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/rbacRole/show", {
    params
  });
};
/** 用户own详情 */
export const getUserOneselfShowApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/user/oneself", {
    params
  });
};
/** 用户own修改 */
export const updateUserOneselfApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/user/oneself", {
    data
  });
};
